package com.ccdt.tv.smartrecommend.utils;

import android.text.TextUtils;
import android.util.Log;

import java.util.List;

/**
 * Created by wudz on 2017/10/20.
 */

public class CheckUtils {
    private static String CTAG="CheckUtils";
    public static void checkNoNullObject(Object obj, boolean needThrows,String throwStr)
    {
        if(obj==null)
        {
            Log.i(CTAG,throwStr);
            if(needThrows) {
                throw new RuntimeException(throwStr);
            }
        }
    }
    public static boolean checkNonNullString(String checkStr,String defaultStr,boolean needThrows,String throwStr)
    {
        if(TextUtils.isEmpty(checkStr)) {
            Log.i(CTAG,throwStr+",error value is "+checkStr);
            if(needThrows) {
                throw new RuntimeException(throwStr+",error value is "+checkStr);
            }
            checkStr=defaultStr;
            return true;
        }
        return false;
    }
    public static void  checkIntInValues2(int checkInt,int values1,int values2, boolean needThrows, String throwStr)
    {
        checkIntInValues(checkInt,values1,values2,Integer.MAX_VALUE,Integer.MAX_VALUE,needThrows,throwStr);
    }
    public static void  checkIntInValues3(int checkInt,int values1,int values2,int values3, boolean needThrows, String throwStr)
    {
        checkIntInValues(checkInt,values1,values2,values3,Integer.MAX_VALUE,needThrows,throwStr);
    }
    public static void checkIntInValues(int checkInt,int values1,int values2,int values3,int values4,boolean needThrows, String throwStr)
    {
        if(checkInt==values1
                || checkInt==values2
                || checkInt==values3
                || checkInt==values4)
            return;
        Log.i(CTAG,throwStr+",error value is "+checkInt);
        if(needThrows) {
            throw new RuntimeException(throwStr+",error value is "+checkInt);
        }
    }
    public static void checkIntRange(int checkInt, int defalutInt, int startInt, int endInt, boolean needThrows, String throwStr)
    {
        if(checkInt<startInt || checkInt>endInt) {
            Log.i(CTAG,throwStr+",error value is "+checkInt);
            if(needThrows) {
                throw new RuntimeException(throwStr+",error value is "+checkInt);
            }
            checkInt=defalutInt;
        }
    }
    public static void checkNonNullList(List<? extends Object> checkList,List<? extends Object> defaultList,boolean needThrows,String throwStr)
    {
        if(checkList==null)
        {
            Log.i(CTAG,throwStr+", list is null!");
            if(needThrows) {
                throw new RuntimeException(throwStr+", list is null!");
            }
            checkList=defaultList;
        }
    }
}
